home *** CD-ROM | disk | FTP | other *** search
/ Mastering Public Speaking / Mastering Public Speaking.iso / pc / Click Here.exe / Click Here.dxr / Internal_29_Slide In-Out.ls < prev    next >
Encoding:
Text File  |  2003-05-13  |  6.7 KB  |  188 lines

  1. property pSprite, pStart, pActive, pCompleteCycles, pVector, pDestination, pOrigin, pSlid, pDirection, pAuto, pPointH, pPointV, pCycles, pPeriodBase, pPeriod
  2.  
  3. on getBehaviorDescription me
  4.   return "SLIDE IN/OUT" & RETURN & RETURN & "Slides a sprite from one position to another. " & "Place the sprite on stage in its ending position. " & "Then choose whether the sprite should first appear at maximum (slid in) or minimum (slid out) values, when the fading should start, the minimum and maximum slide values, the number of times it should slide, and how fast it should slide. " & "The slide can be activated automatically in the first frame, by a click on the sprite, or by sending the sprite an mSlideActivate message" & RETURN & RETURN & "PERMITTED MEMBER TYPES:" & RETURN & "animated GIF, bitmap, Flash, shape, text, vector shape" & RETURN & RETURN & "PARAMETERS:" & RETURN & "* Slide in or out?" & RETURN & "* Slide direction" & RETURN & "* What event initiates slide? (automatic, click, or message)" & RETURN & "* Number of slide cycles" & RETURN & "* Time between 'in' and 'out' positions in seconds" & RETURN & RETURN & "Set the number of slide cycles to -1 if you want an endless loop, to 0 if the slide should happen once, or to 1 to slide in and then back out."
  5. end
  6.  
  7. on getBehaviorTooltip me
  8.   return "Slides a sprite from one position to another." & RETURN & RETURN & "The 'in' position of the slide is determined by the sprite's position on the stage; the 'out' position is set in the Parameters dialog. " & "The 'out' position can be set by the author to be a specific point on (or off) the Stage, or it can automatically calculated as a point off the Stage relative to the 'in' position."
  9. end
  10.  
  11. on beginSprite me
  12.   pSlid = resolve(pSlid)
  13.   pDirection = resolve(pDirection)
  14.   pAuto = resolve(pAuto)
  15.   mInitialize(me)
  16. end
  17.  
  18. on resolve prop
  19.   case prop of
  20.     pSlid:
  21.       choiceslist = ["In", "Out"]
  22.       lookup = [#in, #out]
  23.     pDirection:
  24.       choiceslist = ["Point", "Top", "Bottom", "Left", "Right", "Top Left", "Top Right", "Bottom Left", "Bottom Right"]
  25.       lookup = [#point, #top, #bottom, #left, #right, #topLeft, #topRight, #bottomLeft, #bottomRight]
  26.     pAuto:
  27.       choiceslist = ["Automatic", "Click", "Message"]
  28.       lookup = [#automatic, #click, #message]
  29.   end case
  30.   return lookup[findPos(choiceslist, prop)]
  31. end
  32.  
  33. on prepareFrame me
  34.   mUpdate(me)
  35. end
  36.  
  37. on mouseUp me
  38.   if pAuto = #click then
  39.     mActivate(me)
  40.   end if
  41. end
  42.  
  43. on mInitialize me
  44.   pSprite = sprite(me.spriteNum)
  45.   vMember = pSprite.member
  46.   vMemberType = vMember.type
  47.   pActive = #off
  48.   pCompleteCycles = 0.5
  49.   pPeriod = pPeriodBase * 1000
  50.   pOrigin = pSprite.loc
  51.   vTopDiff = pSprite.bottom - pSprite.locV
  52.   vBottomDiff = pSprite.locV - pSprite.top
  53.   vLeftDiff = pSprite.right - pSprite.locH
  54.   vRightDiff = pSprite.locH - pSprite.right
  55.   case pDirection of
  56.     #point:
  57.       pDestination = point(pPointH, pPointV)
  58.     #top:
  59.       pDestination = point(pSprite.locH, -vTopDiff)
  60.     #bottom:
  61.       pDestination = point(pSprite.locH, (the stage).rect.height + vBottomDiff)
  62.     #left:
  63.       pDestination = point(-vLeftDiff, pSprite.locV)
  64.     #right:
  65.       pDestination = point((the stage).rect.width + vLeftDiff, pSprite.locV)
  66.     #topLeft:
  67.       pDestination = point(-vLeftDiff, -vTopDiff)
  68.     #topRight:
  69.       pDestination = point((the stage).rect.width + vLeftDiff, -vTopDiff)
  70.     #bottomLeft:
  71.       pDestination = point(-vLeftDiff, (the stage).rect.height + vBottomDiff)
  72.     #bottomRight:
  73.       pDestination = point((the stage).rect.width + vLeftDiff, (the stage).rect.height + vBottomDiff)
  74.   end case
  75.   pVector = pDestination - pOrigin
  76.   if pSlid = #in then
  77.     pSprite.loc = pDestination
  78.   else
  79.     pSprite.loc = pOrigin
  80.   end if
  81.   if pAuto = #automatic then
  82.     mActivate(me)
  83.   end if
  84. end
  85.  
  86. on mUpdate me
  87.   if pActive <> #off then
  88.     vMillis = the milliSeconds
  89.     vElapsed = vMillis - pStart
  90.     if vElapsed >= pPeriod then
  91.       case pActive of
  92.         #in:
  93.           pSprite.loc = pOrigin
  94.         #out:
  95.           pSprite.loc = pDestination
  96.       end case
  97.       pActive = #off
  98.       mCheckCycle(me)
  99.     else
  100.       vVector = pVector * vElapsed / pPeriod
  101.       case pActive of
  102.         #in:
  103.           pSprite.loc = pDestination - vVector
  104.         #out:
  105.           pSprite.loc = pOrigin + vVector
  106.       end case
  107.     end if
  108.   end if
  109. end
  110.  
  111. on mActivate me
  112.   if pVector <> point(0, 0) then
  113.     case pSlid of
  114.       #in:
  115.         mSlideIn(me)
  116.       #out:
  117.         mSlideOut(me)
  118.     end case
  119.   end if
  120. end
  121.  
  122. on mCheckCycle me
  123.   vContinue = 0
  124.   case pCycles of
  125.     (-1):
  126.       vContinue = 1
  127.     0:
  128.       vContinue = 0
  129.     otherwise:
  130.       pCompleteCycles = pCompleteCycles + 0.5
  131.       if integer(pCompleteCycles) <= pCycles then
  132.         vContinue = 1
  133.       end if
  134.   end case
  135.   if vContinue then
  136.     if pSprite.loc = pOrigin then
  137.       mSlideOut(me)
  138.     else
  139.       mSlideIn(me)
  140.     end if
  141.   end if
  142. end
  143.  
  144. on mSlideIn me
  145.   mSlide(me, #in)
  146. end
  147.  
  148. on mSlideOut me, vTarget
  149.   mSlide(me, #out)
  150. end
  151.  
  152. on mSlide me, vInOut
  153.   pActive = vInOut
  154.   pStart = the milliSeconds
  155. end
  156.  
  157. on mSlideActivate me
  158.   if pAuto = #message then
  159.     mActivate(me)
  160.   end if
  161. end
  162.  
  163. on isOKToAttach me, aSpriteType, aSpriteNum
  164.   case aSpriteType of
  165.     #graphic:
  166.       return getPos([#text, #bitmap, #animGif, #vectorShape, #flash, #shape, #field, #picture], sprite(aSpriteNum).member.type) <> 0
  167.     #script:
  168.       return 0
  169.   end case
  170. end
  171.  
  172. on getPropertyDescriptionList me
  173.   vStage = rect(0, 0, (the stage).rect.width, (the stage).rect.height)
  174.   vPDList = [:]
  175.   setaProp(vPDList, #pSlid, [#comment: "Slide in or out?", #format: #string, #default: "In", #range: ["In", "Out"]])
  176.   setaProp(vPDList, #pDirection, [#comment: "Automatic slide direction (point uses values entered below)", #format: #string, #default: "Point", #range: ["Point", "Top", "Bottom", "Left", "Right", "Top Left", "Top Right", "Bottom Left", "Bottom Right"]])
  177.   setaProp(vPDList, #pPointH, [#comment: "Point Horizontal Value", #format: #integer, #default: vStage.width / 2, #range: [#min: -vStage.width, #max: vStage.width * 2]])
  178.   setaProp(vPDList, #pPointV, [#comment: "Point Vertical Value", #format: #integer, #default: vStage.height / 2, #range: [#min: -vStage.height, #max: vStage.height * 2]])
  179.   setaProp(vPDList, #pAuto, [#comment: "Start automatically, when clicked, or by message?", #default: "Automatic", #format: #string, #range: ["Automatic", "Click", "Message"]])
  180.   setaProp(vPDList, #pCycles, [#comment: "Slide cycles (0 = one slide only, -1 = repeat forever)", #format: #integer, #default: 0, #range: [#min: -1, #max: 10]])
  181.   setaProp(vPDList, #pPeriodBase, [#comment: "Time period for slide (seconds)", #format: #float, #default: 2.0, #range: [#min: 0.25, #max: 15.0]])
  182.   return vPDList
  183. end
  184.  
  185. on mPermittedMemberTypes me
  186.   return [#text, #bitmap, #animGif, #vectorShape, #flash, #shape, #field, #picture]
  187. end
  188.